import 'dart:math';

import 'package:flutter/material.dart';

const TAG = 'ProviderState\t';

class ProviderState extends StatefulWidget {
  const ProviderState({super.key});

  @override
  State<ProviderState> createState() => _ProviderStateState();
}

class _ProviderStateState extends State<ProviderState> {
  var count = 0;
  var name = 'name';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('计数器-状态')),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          countWidget(),
          nameWidget(),
        ],
      ),
    );
  }

  updateCount() {
    count = Random().nextInt(100);
    setState(() {});
  }

  updateName() {
    setState(() {
      name = 'name_${Random().nextInt(100) + 100}';
    });
  }

  countWidget() {
    print('${TAG}countWidget');
    return OutlinedButton(
      child: Text('count: ${count}'),
      onPressed: () {
        updateCount();
      },
    );
  }

  nameWidget() {
    print('${TAG}nameWidget');
    return OutlinedButton(
      child: Text('name: ${name}'),
      onPressed: () {
        updateName();
      },
    );
  }
}
